package com.fuze.energy;

import com.fuze.energy.netty.TcpServer;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.concurrent.*;

/**
 * @author sepc_
 */
@Slf4j
@MapperScan(basePackages = {"com.fuze.energy.mapper"})
@EnableSwagger2
@EnableSwaggerBootstrapUI
@EnableScheduling
@EnableAsync
@SpringBootApplication
public class HwgBackendApplication {

    public static void main(String[] args) {
        SpringApplication.run(HwgBackendApplication.class, args);
        log.info("= = = = = = = = Application Started Successes = = = = = = = = =");
        ThreadFactory namedThreadFactory = (new ThreadFactoryBuilder()).setNameFormat("netty-start-%d").build();
        ExecutorService cachedThread = new ThreadPoolExecutor(2,
                5,
                0L,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(2),
                namedThreadFactory,
                new ThreadPoolExecutor.DiscardPolicy());
        cachedThread.execute(() -> TcpServer.getInstance().start());
        cachedThread.shutdown();
    }
}
